<template>
	<view>
		<template v-for="(item,index) of datalist">
			<wm-order @operation="operation" @hdzc="hdzc" :co="item" :key="index"/>
		</template>
		<mg-modal :ismr="true" v-model="showhdzc" width="630rpx" :z-index="3000">
			<view class="bf bs10">
				<view class="p3 c9">
					<block v-if="hdzcInfo.t == 1">
						<view class="t-c f32 c0 mb20">优惠合计详情</view>
						<view class="p10 f-y-c">
							<view class="f-1">新客立减</view>
							<view>-{{ `${hdzcInfo.osl + hdzcInfo.v.newMoney}` }}</view>
						</view>
						<view class="p10 f-y-c">
							<view class="f-1">门店满减</view>
							<view>-{{ `${hdzcInfo.osl + hdzcInfo.v.preferentialMoney}` }}</view>
						</view>
						<view class="p10 f-y-c">
							<view class="f-1">门店优惠券</view>
							<view>-{{ `${hdzcInfo.osl + hdzcInfo.v.couponPreferential}` }}</view>
						</view>
						<view class="p10 f-y-c">
							<view class="f-1">平台优惠券</view>
							<view>-{{ `${hdzcInfo.osl + (hdzcInfo.v.platformCouponPreferential || '0.00')}` }}</view>
						</view>
						<view class="p10 f-y-c">
							<view class="f-1">配送费优惠</view>
							<view>-{{ `${hdzcInfo.osl + hdzcInfo.v.deliveryPreferential}` }}</view>
						</view>
						<view class="p10 f-y-c c0">
							<view class="f-1">总计</view>
							<view>-{{ `${hdzcInfo.osl + hdzcInfo.v.discount}` }}</view>
						</view>
					</block>
					<block v-else-if="hdzcInfo.t == 2">
						<view class="t-c f32 c0 mb20">预计收入详情</view>
						<view class="p10 f-y-c">
							<view class="f-1">商品价格</view>
							<view>{{ `${hdzcInfo.osl + hdzcInfo.v.originMoney}` }}</view>
						</view>
						<view class="p10 f-y-c">
							<view class="f-1">配送费</view>
							<view>{{ `${hdzcInfo.osl + hdzcInfo.v.deliveryMoney}` }}</view>
						</view>
						<view class="p10 f-y-c">
							<view class="f-1">包装费</view>
							<view>{{ `${hdzcInfo.osl + hdzcInfo.v.boxMoney}` }}</view>
						</view>
						<view class="p10 f-y-c c0">
							<view class="f-1">本单收入</view>
							<view>{{ `${hdzcInfo.osl + (hdzcInfo.v.storeActualMoney || '0.00')}` }}</view>
						</view>
					</block>
				</view>
				<view class="hlt" style="height: 100rpx;">
					<button hover-class="be" class="tcbtn f-1 bf h100 f28 f-c" :style="{ color: tColor }" @click.stop="showhdzc = false">我知道了</button>
				</view>
			</view>
		</mg-modal>
	</view>
</template>

<script>
import { mapState, mapActions } from 'vuex';
import wmOrder from '@/components/template/order/wm-order.vue';
import mgModal from '@/components/common/modal.vue';
export default {
	name: 'wmorder-list',
	components: {
		wmOrder,
		mgModal
	},
	props: {
		datalist: Array
	},
	data() {
		return {
			showhdzc: false,
			hdzcInfo: {}
		};
	},
	computed: mapState(['BLELinkList']),
	methods: {
		qdyy() {
			this.showCancel = false;
			if (this.operationt == 'jjjd') {
				this.qxyy = this.sjjdArr.find(v => v.value == this.yyradio).name;
				this.operation({
					t: 'jjd',
					co: this.orderInfo
				});
			} else {
				this.qxyy = this.jjtkArr.find(v => v.value == this.yyradio).name;
				this.operation({
					t: 'jtk',
					co: this.orderInfo
				});
			}
			// console.log(this.orderInfo, this.operationt, this.qxyy)
		},
		async operation(e) {
			this.orderInfo = e.co;
			this.operationt = e.t;
			let obj = {};
			switch (e.t) {
				case 'ljjd':
					obj = {
						title: '您确认立即接单吗？',
						url: 'ddcz',
						params: {
							orderId: e.co.id,
							type: 'receipt'
						}
					};
					break;
				case 'jjjd':
					obj = {
						title: '您确认拒绝接单吗？',
						url: 'ddcz',
						params: {
							orderId: e.co.id,
							type: 'rejection',
							note: this.qxyy
						}
					};
					break;
				case 'jjjd':
					this.yyradio = '';
					this.yyArr = this.sjjdArr;
					this.showCancel = true;
					return;
				case 'jjtk':
					this.yyradio = '';
					this.yyArr = this.jjtkArr;
					this.showCancel = true;
					return;
				case 'ljps':
					obj = {
						title: '您确认立即配送吗？',
						url: 'ddcz',
						params: {
							orderId: e.co.id,
							type: 'delivery'
						}
					};
					break;
				case 'qrhx':
					obj = {
						title: '您确认收货吗？',
						url: 'ddcz',
						params: {
							orderId: e.co.id,
							type: 'confirm'
						}
					};
					break;
				case 'qrsh':
					obj = {
						title: '您确认收货吗？',
						url: 'ddcz',
						params: {
							orderId: e.co.id,
							type: 'confirm'
						}
					};
					break;
				case 'ddtzz':
					obj = {
						title: '确认通知用户吗？',
						url: 'ddcz',
						params: {
							orderId: e.co.id,
							type: 'task'
						}
					};
					break;
				case 'sdtk':
					obj = {
						title: '您确认退款吗？',
						url: 'ddcz',
						params: {
							orderId: e.co.id,
							type: 'refund'
						}
					};
					break;
				case 'tytk':
					obj = {
						title: '您确认退款吗？',
						url: 'ddcz',
						params: {
							orderId: e.co.id,
							type: 'adoptRefund'
						}
					};
					break;
				case 'jtk':
					obj = {
						title: '您确认拒绝退款吗？',
						url: 'ddcz',
						params: {
							orderId: e.co.id,
							type: 'refuseRefund',
							note: this.qxyy
						}
					};
					break;
				case 'qrcd':
					obj = {
						title: '您确认催单吗？',
						url: 'ddcz',
						params: {
							orderId: e.co.id,
							type: 'confirmReminder'
						}
					};
					break;
				case 'dyj':
					obj = {
						title: '您确认打印此订单吗？',
						url: 'ddcz',
						params: {
							orderId: e.co.id,
							type: 'print'
						}
					};
					break;
			}
			// uni.$emit('abc')
			// return
			// console.log(e, obj)
			try {
				await this.util.modal(obj.title).then(res=>{
					// todo 判断订单需要打印 商家联 后厨联 顾客联 配送联 只需要考虑本地蓝牙打印机配置
					if(obj.title === '您确认打印此订单吗？'){
						uni.$emit('BLEPrinter',this.BLELinkList,this.orderInfo)
					}
				});
			} catch (e) {
				return;
			}
			let data = await this.util.request({
				url: this.api[obj.url],
				method: 'POST',
				mask: 1,
				data: obj.params
			});
			if (data.code === 1) {
				uni.$emit('refreshOrderList');
				this.util.message('操作成功', 3);
			}else{
				this.util.message(data.msg, 3);
			}
		},
		hdzc(e) {
			this.showhdzc = true;
			this.hdzcInfo = e;
		}
	}
};
</script>
<style scoped lang="scss"></style>
